package com.xbongbong.workflow.application;/*/*/

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Locale;

/**
 * 工作流消费者
 * @author 魏荣杰
 * @date 2019/2/22 15:20
 * @since v1.0
 * @version v1.0
 */
@EnableDiscoveryClient
@SpringBootApplication
@MapperScan(basePackages = {"com.xbongbong.*.domain"}, sqlSessionFactoryRef = "sqlSessionFactory")
@ComponentScan(basePackages={"com.xbongbong","com.alibaba.dingtalk.openapi"})
@EnableElasticsearchRepositories(basePackages = "com.xbongbong.paas.elasticsearch")
@EnableFeignClients(basePackages = {"com.xbongbong.paas.manager.feign", "com.xbongbong.pro.message.feign", "com.xbongbong.workflow.feign",  "com.xbongbong.*.feign"})
public class ProWebWorkflowApplication {
    private static final Logger LOG = LoggerFactory.getLogger(ProWebWorkflowApplication.class);

    @Resource
    private RestTemplateBuilder builder;

    /**
     * 使用RestTemplateBuilder来实例化RestTemplate对象，spring默认已经注入了RestTemplateBuilder实例
     * @return RestTemplate实例
     */
    @Bean
    public RestTemplate restTemplate() {
        return builder.build();
    }

    public static void main(String[] args) {

        System.setProperty("es.set.netty.runtime.available.processors", "false");
        try {
            // 设置系统线程默认语言包，LocaleContextHolder spring工具
            LocaleContextHolder.setDefaultLocale(Locale.CHINA);

            SpringApplication.run(ProWebWorkflowApplication.class, args);
        } catch (Exception e) {
            LOG.error("ProWebWorkflowApplication启动失败", e);
        }
    }
}
